using System.IO;
using System.Reflection;
using GrapeCity.Documents.Excel;
using System;
using System.Data;

namespace GrapeCity.Documents.Excel.Examples.Templates.Properties.SortProperty.TemplateMultiColumnSort
{
    class Program
    {
        static void Main(string[] args)
        {
			//create a new workbook
			var workbook = new GrapeCity.Documents.Excel.Workbook();
			
			//Load template file from resource
			var templateFile = GetResourceStream("xlsx\\Template_MultiColumnSort.xlsx");
			workbook.Open(templateFile);
			
			#region Init Data
			var datasource = new DataTable();
			datasource.Columns.Add(new DataColumn("OrderId", typeof(string)));
			datasource.Columns.Add(new DataColumn("Customer", typeof(string)));
			datasource.Columns.Add(new DataColumn("Date", typeof(DateTime)));
			datasource.Columns.Add(new DataColumn("Sales", typeof(double)));
			
			datasource.Rows.Add("10001", "Noah Taylor", new DateTime(2024, 1, 20), 1620.25);
			datasource.Rows.Add("10002", "William Smith", new DateTime(2024, 1, 20), 5620.25);
			datasource.Rows.Add("10003", "Sophia Miller", new DateTime(2024, 1, 20), 3354.50);
			datasource.Rows.Add("10004", "Noah Taylor", new DateTime(2024, 1, 23), 3563.00);
			datasource.Rows.Add("10005", "Ava Johnson", new DateTime(2024, 1, 23), 1500.00);
			datasource.Rows.Add("10006", "Ava Davis", new DateTime(2024, 1, 24), 3500.00);
			datasource.Rows.Add("10007", "Emma Brown", new DateTime(2024, 1, 24), 8865.50);
			datasource.Rows.Add("10008", "Isabella Taylor", new DateTime(2024, 1, 24), 4332.05);
			datasource.Rows.Add("10009", "Noah Anderson", new DateTime(2024, 1, 25), 5568.54);
			datasource.Rows.Add("10010", "William Smith", new DateTime(2024, 1, 26), 2659.56);
			datasource.Rows.Add("10011", "Liam Taylor", new DateTime(2024, 1, 26), 6659.56);
			datasource.Rows.Add("10012", "Olivia Smith", new DateTime(2024, 1, 26), 4321.05);
			datasource.Rows.Add("10013", "Emma Brown", new DateTime(2024, 1, 27), 6521.52);
			datasource.Rows.Add("10014", "Ava Jones", new DateTime(2024, 1, 28), 4321.05);
			datasource.Rows.Add("10015", "Liam Johnson", new DateTime(2024, 1, 28), 5542.02);
			#endregion
			
			//Init template global settings
			workbook.Names.Add("TemplateOptions.KeepLineSize", "true");
			
			//Add data source
			workbook.AddDataSource("ds", datasource);
			//Invoke to process the template
			workbook.ProcessTemplate();
			        
			// Save to an excel file
			workbook.Save("TemplateMultiColumnSort.xlsx");

        }

		static Stream GetResourceStream(string resourcePath)
        {
            string resource = "TemplateMultiColumnSort.Resource." + resourcePath.Replace("\\", ".");
            var assembly = typeof(Program).GetTypeInfo().Assembly;
            return assembly.GetManifestResourceStream(resource);
        }

    }
}